//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#include <QBoxLayout>
#include <QFrame>
#include <QGroupBox>
#include <QToolBox>
#include "mainview.h"
#include "objectnameview.h"
#include "objtreeview.h"
#include "ptgenericview.h"
#include "pttimemarklistview.h"
#include "ptpage.h"
//
PTPage::PTPage(MainView *p_main_view,QWidget *p_parent)
:
   ObjectPage(p_main_view,p_parent),
   objects_view(new ObjTreeView(p_main_view,0,true,false)),
   generic_view(new PTGenericView(this)),
   tm_view(new PTTimeMarkListView(this))
{
   objects_view->set_attr_group(get_attr_group());
   generic_view->set_attr_group(get_attr_group());
   tm_view->set_attr_group(get_attr_group());
   //
   QToolBox *toolbox=new QToolBox();
   //toolbox->setTabSpacing(0);
   //QToolBox draws over its frame
   //toolbox->setFrameStyle(QToolBox::Raised);
   //toolbox->setFrameShape(QToolBox::Box);
   //toolbox->setMidLineWidth(2);
   toolbox->addItem(build_contained_widget(),QIcon(),tr("contained objects"));
   toolbox->addItem(build_generic_widget(),QIcon(),tr("generic"));
   toolbox->addItem(build_texture_widget(),QIcon(),tr("shape&&texture"));
   toolbox->addItem(build_tm_widget(),QIcon(),tr("time marks"));
   //
   QVBoxLayout *l=new QVBoxLayout();
   l->addWidget(toolbox);
   setLayout(l);
}
//
void PTPage::handle_activate()
{
   objects_view->activate_actions();
}
void PTPage::handle_deactivate()
{
   objects_view->deactivate_actions();
}
//
void PTPage::set_pt(model::ParticleTemplate *p_pt)
{
   set_object(p_pt);
}
model::ParticleTemplate *PTPage::get_pt() const
{
   return static_cast<model::ParticleTemplate*>(get_object());
}
//
QWidget *PTPage::build_contained_widget()
{
   return objects_view;
}
QWidget *PTPage::build_generic_widget()
{
   QFrame *const w=new QFrame();
   w->setFrameStyle(QFrame::Panel|QFrame::Sunken);
   QVBoxLayout *const tl=new QVBoxLayout();
   //tl->setSpacing(1);
   //
   QGroupBox *b=new QGroupBox(tr("name"));
   QVBoxLayout *l=new QVBoxLayout();
   //l->setContentsMargins(1,1,1,1);
   ObjectNameView *name_view=new ObjectNameView();
   name_view->set_attr_group(get_attr_group());
   l->addWidget(name_view);
   b->setLayout(l);
   tl->addWidget(b);
   //
   b=new QGroupBox(tr("lifetime"));
   l=new QVBoxLayout();
   l->addWidget(generic_view->get_life_time_widget());
   b->setLayout(l);
   tl->addWidget(b);
   //
   b=new QGroupBox(tr("visible"));
   l=new QVBoxLayout();
   //generic_view->get_visible_widget()->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Fixed);
   //l->setContentsMargins(1,1,1,1);
   l->addWidget(generic_view->get_visible_widget());
   b->setLayout(l);
   tl->addWidget(b);
   //
   b=new QGroupBox(tr("density"));
   l=new QVBoxLayout();
   l->addWidget(generic_view->get_density_widget());
   b->setLayout(l);
   tl->addWidget(b);
   //
   b=new QGroupBox(tr("gravitation_enabled"));
   l=new QVBoxLayout();
   l->addWidget(generic_view->get_gravitation_enabled_widget());
   b->setLayout(l);
   tl->addWidget(b);
   //
   b=new QGroupBox(tr("friction_enabled"));
   l=new QVBoxLayout();
   l->addWidget(generic_view->get_friction_enabled_widget());
   b->setLayout(l);
   tl->addWidget(b);
   //
   tl->addStretch(1);
   w->setLayout(tl);
   return w;
}
QWidget *PTPage::build_texture_widget()
{
   QFrame *const w=new QFrame();
   w->setFrameStyle(QFrame::Panel|QFrame::Sunken);
   QVBoxLayout *const tl=new QVBoxLayout();
   //
   QGroupBox *b=new QGroupBox(tr("shape"));
   QVBoxLayout *l=new QVBoxLayout();
   l->addWidget(generic_view->get_shape_widget());
   b->setLayout(l);
   tl->addWidget(b);
   //
   b=new QGroupBox(tr("texture"));
   l=new QVBoxLayout();
   l->addWidget(generic_view->get_texture_file_widget());
   b->setLayout(l);
   tl->addWidget(b);
   //
   b=new QGroupBox(tr("tiles X"));
   l=new QVBoxLayout();
   l->addWidget(generic_view->get_tile_s_widget());
   b->setLayout(l);
   tl->addWidget(b);
   //
   b=new QGroupBox(tr("tiles Y"));
   l=new QVBoxLayout();
   l->addWidget(generic_view->get_tile_t_widget());
   b->setLayout(l);
   tl->addWidget(b);
   //
   b=new QGroupBox(tr("tile count"));
   l=new QVBoxLayout();
   l->addWidget(generic_view->get_num_tiles_widget());
   b->setLayout(l);
   tl->addWidget(b);
   //
   b=new QGroupBox(tr("anim mode"));
   l=new QVBoxLayout();
   l->addWidget(generic_view->get_tile_speed_mode_widget());
   b->setLayout(l);
   tl->addWidget(b);
   //
   tl->addStretch(1);
   w->setLayout(tl);
   return w;
}
QWidget *PTPage::build_tm_widget()
{
   QFrame *const w=new QFrame();
   w->setFrameStyle(QFrame::Panel|QFrame::Sunken);
   QVBoxLayout *const tl=new QVBoxLayout();
   //
   tl->addWidget(tm_view->get_add_widget());
   tl->addLayout(tm_view->get_main_layout());
   tl->addWidget(tm_view->get_status_widget());
   tl->addStretch(1);
   w->setLayout(tl);
   return w;
}
